/* Why Geographically-Targeted Spending Under Closed-List Proportional Representation Favors Marginal Districts
Author: Amy Catalinac and Lucia Motolinia*/
*******Replication Code Tables*******

clear all
set more off
cd "D:\Users\Lucia\Dropbox\NYU\Papers\Catalinac & Motolinia\Note\_Replication_\"

use "data_PR_analysis_komblocs13Sep212020.dta", clear

*Table 5*
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
xtreg `x' bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year  if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/T5.tex", keep(bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) replace
xtreg `x' bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year  if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/T5.tex", keep(bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' bb bb_vsharevp bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density  i.year  if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/T5.tex", keep(bb bb_vsharevp_pr bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
}

*Table 6*
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' bb bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district  if split_mun_jed==0, robust cluster(pr_bloc) 
outreg2 using "output/T6.tex", keep(bb bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc) dec(3) onecol se br symbol(***, **, *) replace
reg `x' bb bb_vsharevp hi disceif disprimary disneedy  disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district  if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/T6.tex", keep(bb bb_vsharevp hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc) dec(3) onecol se br symbol(***, **, *) append
reg `x' bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/T6.tex", keep(bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc) dec(3) onecol se br symbol(***, **, *) append
}

*Appendix C: Control for Natural Disasters
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
xtreg `x' bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year c.natdis if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AC1.tex", keep(bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density natdis) dec(3) onecol se br symbol(***, **, *) replace
xtreg `x' bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year c.natdis if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AC1.tex", keep(bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density natdis) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' bb bb_vsharevp bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density  i.year c.natdis if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AC1.tex", keep(bb bb_vsharevp_pr bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density natdis) dec(3) onecol se br symbol(***, **, *) append
}

local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' bb bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district c.natdis if split_mun_jed==0, robust cluster(pr_bloc) 
outreg2 using "output/AC2.tex", keep(bb bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc c.natdis) dec(3) onecol se br symbol(***, **, *) replace
reg `x' bb bb_vsharevp hi disceif disprimary disneedy  disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district c.natdis if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AC2.tex", keep(bb bb_vsharevp hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc c.natdis) dec(3) onecol se br symbol(***, **, *) append
reg `x' bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district c.natdis if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AC2.tex", keep(bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc c.natdis) dec(3) onecol se br symbol(***, **, *) append
}

local varlist "newf1logngaid_pc"
foreach x in `varlist'{
xtreg `x' bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year i.seis if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AC3.tex", keep(bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.seis) dec(3) onecol se br symbol(***, **, *) replace
xtreg `x' bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year i.seis if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AC3.tex",keep(bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.seis) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' bb bb_vsharevp bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density  i.year i.seis if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AC3.tex", keep(bb bb_vsharevp_pr bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.seis) dec(3) onecol se br symbol(***, **, *) append
}

local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' bb bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district i.seis if split_mun_jed==0, robust cluster(pr_bloc) 
outreg2 using "output/AC4.tex",  keep(bb bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.seis) dec(3) onecol se br symbol(***, **, *) replace
reg `x' bb bb_vsharevp hi disceif disprimary disneedy  disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district i.seis if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AC4.tex", keep(bb bb_vsharevp hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.seis) dec(3) onecol se br symbol(***, **, *) append
reg `x' bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district i.seis if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AC4.tex", keep(bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.seis) dec(3) onecol se br symbol(***, **, *) append
}

local varlist "newf1logngaid_pc"
foreach x in `varlist'{
xtreg `x' bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year c.mag if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AC5.tex", keep(bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density mag) dec(3) onecol se br symbol(***, **, *) replace
xtreg `x' bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year c.mag if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AC5.tex", keep(bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density mag) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' bb bb_vsharevp bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density  i.year c.mag if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AC5.tex", keep(bb bb_vsharevp_pr bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density mag) dec(3) onecol se br symbol(***, **, *) append
}

local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' bb bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district c.magnitude if split_mun_jed==0, robust cluster(pr_bloc) 
outreg2 using "output/AC6.tex", keep(bb bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc c.magnitude) dec(3) onecol se br symbol(***, **, *) replace
reg `x' bb bb_vsharevp hi disceif disprimary disneedy  disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district c.magnitude if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AC6.tex", keep(bb bb_vsharevp hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc c.magnitude) dec(3) onecol se br symbol(***, **, *) append
reg `x' bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district c.magnitude if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AC6.tex", keep(bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc c.magnitude) dec(3) onecol se br symbol(***, **, *) append
}

*Appendix D: Another Measure of SSD Marginality (Zombie Control)
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
xtreg `x' bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year c.zombie if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AD1.tex", keep(bb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density zombie) dec(3) onecol se br symbol(***, **, *) replace
xtreg `x' bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year c.zombie if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AD1.tex", keep(bb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density zombie) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' bb bb_vsharevp bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density  i.year c.zombie if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AD1.tex", keep(bb bb_vsharevp_pr bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density zombie) dec(3) onecol se br symbol(***, **, *) append
}

local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' bb bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum logngaid_pc i.year i.district c.zombie if split_mun_jed==0, robust cluster(pr_bloc) 
outreg2 using "output/AD2.tex", keep(bb bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum logngaid_pc zombie) dec(3) onecol se br symbol(***, **, *) replace
reg `x' bb bb_vsharevp hi disceif disprimary disneedy  disdensity logdispop logdisincomepc lognum logngaid_pc i.year i.district c.zombie if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AD2.tex", keep(bb bb_vsharevp hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum logngaid_pc zombie) dec(3) onecol se br symbol(***, **, *) append
reg `x' bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum logngaid_pc i.year i.district c.zombie if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AD2.tex", keep(bb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum logngaid_pc zombie) dec(3) onecol se br symbol(***, **, *) append
}

*Appendix E: Alternative Explanations*
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
xtreg `x' dd bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AE1.tex", keep(dd bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) replace
xtreg `x' dd bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AE1.tex", keep(dd bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' dd bb_vsharevp bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AE1.tex", keep(dd bb_vsharevp_pr bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
}

local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' dd bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AE2.tex", keep(dd bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc) dec(3) onecol se br symbol(***, **, *) replace
reg `x' dd bb_vsharevp hi disceif disprimary disneedy  disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AE2.tex", keep(dd bb_vsharevp hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc) dec(3) onecol se br symbol(***, **, *) append
reg `x' dd bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district if split_mun_jed==0, robust cluster(pr_bloc) 
outreg2 using "output/AE2.tex", keep(dd bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc) dec(3) onecol se br symbol(***, **, *) append
}

*Appendix F: Excluding PR Blocs Where the Ruling Party Captured the Last Seat
local varlist "newf1logngaid_pc"
foreach x in `varlist'{
xtreg `x' cb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AF1.tex", keep(cb bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) replace
xtreg `x' cb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year if split_mun_jed==0,fe robust cluster(pr_bloc) 
outreg2 using "output/AF1.tex", keep(cb bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
xtreg `x' cb bb_vsharevp bb_vsharevp_pr logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density i.year if split_mun_jed==0 ,fe robust cluster(pr_bloc) 
outreg2 using "output/AF1.tex", keep(cb bb_vsharevp_pr bb_vsharevp logngaid_pc mun_ceif lnpop logincome_pc needy_pc primary_pc mun_population_density) dec(3) onecol se br symbol(***, **, *) append
}

local varlist "newf1logngaid_pc"
foreach x in `varlist'{
reg `x' cb bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AF2.tex", keep(cb bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc) dec(3) onecol se br symbol(***, **, *) replace
reg `x' cb bb_vsharevp disceif hi disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district if split_mun_jed==0, robust cluster(pr_bloc) 
outreg2 using "output/AF2.tex", keep(cb bb_vsharevp hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc) dec(3) onecol se br symbol(***, **, *) append
reg `x' cb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy disdensity logdispop logdisincomepc lognum competitiv logngaid_pc i.year i.district if split_mun_jed==0 , robust cluster(pr_bloc) 
outreg2 using "output/AF2.tex", keep(cb bb_vsharevp bb_vsharevp_pr hi disceif disprimary disneedy dismal disdensity logdispop logdisincomepc lognum competitiv logngaid_pc) dec(3) onecol se br symbol(***, **, *) append
}

*******Replication Code Figures*******
use "blocs.dta", clear

*Figure 1
replace newf1logngaid_pc = . in 12 /*No Tohoku2012 */
replace newf1logngaid_pc2 = . in 12

twoway (lfitci newf1logngaid_pc2  bloc_rankpos, lwidth(medthick)) ///
 (scatter newf1logngaid_pc2 bloc_rankpos, xlabel(1(2)12) mlabel(bloc_year) mlabposition(3) msymbol(oh) mcolor(black) mlabcolor(black) mlabsize(vsmall)), ///
 legend(off) ytitle(Log(Transfers(d,t+1))) xtitle(PR district rank(t)) graphregion(color(white)) name(g0)
twoway (lfitci newf1logngaid_pc2 vd if votesneeded<1000000, lwidth(medthick)) ///
 (scatter newf1logngaid_pc2 vd if votesneeded<1000000, xlabel(0(100)850) mlabel(bloc_year) mlabposition(3) msymbol(oh) mcolor(black) mlabcolor(black) mlabsize(vsmall)), ///
 legend(off) ytitle(Log(Transfers(d,t+1))) xtitle(Votes Needed to win an Extra seat (thousands)) graphregion(color(white)) name(g1)
graph combine g0 g1, scheme(s1mono) graphregion(color(white))
graph drop _all 

*Appendix B: Figure B1
use "blocs.dta", clear
twoway (lfitci newf1logngaid_pc2  bloc_rankpos, lwidth(medthick)) ///
 (scatter newf1logngaid_pc2 bloc_rankpos, xlabel(1(2)12) mlabel(bloc_year) mlabposition(3) msymbol(oh) mcolor(black) mlabcolor(black) mlabsize(vsmall)), ///
 legend(off) ytitle(Log(Transfers(d,t+1))) xtitle(PR district rank(t)) graphregion(color(white)) name(g0)
twoway (lfitci newf1logngaid_pc2 vd if votesneeded<1000000, lwidth(medthick)) ///
 (scatter newf1logngaid_pc2 vd if votesneeded<1000000, xlabel(0(100)850) mlabel(bloc_year) mlabposition(3) msymbol(oh) mcolor(black) mlabcolor(black) mlabsize(vsmall)), ///
 legend(off) ytitle(Log(Transfers(d,t+1))) xtitle(Votes Needed to win an Extra seat (thousands)) graphregion(color(white)) name(g1)
graph combine g0 g1, scheme(s1mono) graphregion(color(white))
graph drop _all 

